<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/21
 * Time: 9:30
 */

namespace app\admin\controller;
use app\admin\controller\Base;
use app\admin\model\Bp;
use app\admin\model\Register;
use app\admin\model\Cj;
use app\admin\model\Gbt;
use app\admin\model\Fjxx;
use think\Db;
use think\Config;
use app\index\controller\Index;

class Cjgl extends Base
{
    public function index(){
        $list = Register::alias('a')
            ->join('register_cb c','a.id=c.reg_id','LEFT')
            ->join('register_gbt d','a.id=d.reg_id','LEFT')
            ->join('register_cj e','a.id=e.reg_id','LEFT')
            ->field('a.*,c.cbrq,c.ydl,c.ydlc,c.ydlfy,c.cbfs,c.cbfy,
                        d.gbt,d.gbtfy,e.zydqfy,e.dbfy,e.hqfy')
            ->where('djbz',1)       // 只显示车间订单
            ->where('cjtjcwbz',0)   // 显示未提交财务的订单
            ->where('a.sy|a.xm|a.sfzh|a.jtzz|a.lxr|a.lxdh|a.zbr|a.lxrsfz|a.kkszd','like','%'.$this->request->param('keywords').'%')
            ->select();
        $qtlist = Register::alias('a')
            ->join('register_cs b','a.id=b.reg_id','LEFT')
            ->join('register_cb c','a.id=c.reg_id','LEFT')
            ->join('register_gbt d','a.id=d.reg_id','LEFT')
            ->join('register_js e','a.id=e.reg_id','LEFT')
            ->field('a.*,b.cs_datetime,b.cs_fjid,b.cs_price,
                                c.cbrq,c.ydl,c.ydlc,c.ydlfy,c.cbfs,c.cbfy,
                                d.gbt,d.gbtfy,e.ytysfs_id,e.ytysfs,e.jsfy')
            ->where('djbz',0)       // 只显示前台订单
            ->where('qttjcjbz',1)   // 已经提交车间订单
            ->where('cjtjcwbz',0)   // 显示未提交财务的前台订单
            ->select();
        $totalCounts = Register::where('djbz',1)->count();
        $this->assign('list',$list);
        $this->assign('qtlist',$qtlist);
        $this->assign('totalcounts',$totalCounts);
        return $this->fetch('rcyw/cjgl/index');
    }

    // 新增订单
    public function adddj(){
        // 登记日期
        $this->assign('djrq',date('Y-m-d H:i:s'));
        //  值班人
        $this->assign('zbr',\app\admin\model\Zbr::all());
        //  司仪
        $this->assign('sy',\app\admin\model\Sy::all());
        //  死亡原因
        $this->assign('swyy',\app\admin\model\Swyy::all());
        //  证件
        $this->assign('zj',\app\admin\model\Zj::all());
        //  死亡日期
        $this->assign('swrq',date('Y-m-d'));
        //  证件
        $this->assign('jmlx',\app\admin\model\Jmlx::all());
        //  与逝者关系
        $this->assign('yszgx',\app\admin\model\Yszgx::all());
        //  遗体运送方式
        $this->assign('ytysfs',\app\admin\model\Ytysfs::all());
        //  房间号
        $this->assign('fjxx',\app\admin\model\Fjxx::all(['status'=>0]));
        //  预定炉
        $this->assign('hhl',\app\admin\model\Hhl::all());
        //  出殡方式
        $this->assign('cbfs',\app\admin\model\Cbfs::all());
        //  告别厅
        $this->assign('gbt',\app\admin\model\Gbt::all());
        //  减免类型
        $this->assign('jmlx',\app\admin\model\Jmlx::all());

        return $this->fetch('rcyw/cjgl/adddj');
    }

    public function adddjdo(){
        $data = array(
            'djrq' => $this->request->param('djrq'),
            'xm' => $this->request->param('xm'),                // 姓名
            'xb' => $this->request->param('xb'),                // 性别
            'nl' => $this->request->param('nl'),                // 年龄
            'sfzh' => $this->request->param('sfzh'),            // 身份证号
            'jtzz' => $this->request->param('jtzz'),            // 家庭住址
            'swyy' => $this->request->param('swyy'),            // 死亡原因
            'swrq' => $this->request->param('swrq'),            // 死亡日期
            'lxr' => $this->request->param('lxr'),              // 联系人
            'yszgx' => $this->request->param('yszgx'),          // 与逝者关系
            'lxdh' => $this->request->param('lxdh'),            // 联系电话
            'zj' => $this->request->param('zj'),                // 证件
            'bz' => $this->request->param('bz'),                // 备注
            'cjfj' => $this->request->param('cjfj'),            // 车间附加
            'czybh' => $this->request->session('efing.uname'),  // 操作用户
            'czrq' => time(),                                           // 操作日期时间
            'is_dlcb' => $this->request->param('is_dlcb'),      // 是否定炉出殡
            'djbz' => 1,                                                // 登记部门标志
            'mz' => $this->request->param('mz'),                // 民族
            'is_bdhk' => $this->request->param('is_bdhk'),      // 是否本地户口
            'zzjgdm' => Config::get('app_zzjgdm'),              // 组织机构代码
            'lxrsfz' => $this->request->param('lxrsfz'),        // 联系人身份证
            'jmlx' => $this->request->param('jmlx'),            // 减免类型
            'sfzlx' => $this->request->param('sfzlx'),          // 身份证类型
            'gjhdq' => $this->request->param('gjhdq'),          // 国家或地区
            'dwmc' => Config::get('app_dwmc'),                  // 火化单位名称
            'kkszd' => $this->request->param('kkszd'),          // 户口所在地
        );
        if(count($data)>=24){
            $check = Register::get(['sfzh'=>$data['sfzh']]);
            if($check){
                $res = ['statusCode'=>300,'message'=>'登记信息重复'];
            }else{
                if($insert = Register::create($data)){
                    $indexObj = new Index();
                    if($ddh = $indexObj->formatDddh($insert->id,1)){
                        Register::update(['ddh'=>$ddh,'id'=>$insert->id]);
                    }
                    $user = \app\admin\model\User::get(['uname'=>$this->request->session('efing.uname')]);
                    // 处理出殡
                    if ($data['is_dlcb']==1){
                        $hhl = \app\admin\model\Hhl::get($this->request->param('ydl'));
                        $hhllc = \app\admin\model\Hhllc::get($this->request->param('ydlc'));
                        $cbfs = \app\admin\model\Cbfs::get(['title'=>$this->request->param('cbfs')]);
                        $cb_data = array(
                            'reg_id' => $insert->id,
                            'create_time' => time(),
                            'opt_user' => $user->uname,
                            'opt_datetime' => time(),
                            'opt_name' => $user->name,
                            'cbrq' => strtotime($this->request->param('cbrq')),
                            'ydl' => $hhl->title,
                            'ydlfy' => $hhl->price,
                            'ydlc' => $hhllc->hhllc,
                            'ydlcid' => $hhllc->id,
                            'cbfs' => $this->request->param('cbfs'),
                            'cbfy' => $this->request->param('cbfy'),
                            'cbfsid' => $cbfs->id,
                        );
                        if(count($cb_data)>=13 and false==Db::name('register_cb')->where('reg_id',$insert->id)->find()){
                            Db::name('register_cb')->insert($cb_data);
                        }
                    }
                    // 处理告别厅
                    if($gbt = $this->request->param('gbt')){
                        $gbtfy = $this->request->param('gbtfy');
                        $gbt_data = array(
                            'reg_id' => $insert->id,
                            'create_time' => time(),
                            'opt_user' => $user->uname,
                            'opt_datetime' => time(),
                            'opt_name' => $user->name,
                            'gbt' => $gbt,
                            'gbtfy' => $gbtfy?$gbtfy:0
                        );
                        if(count($gbt_data)>=6 and false==Db::name('register_gbt')->where('reg_id',$insert->id)->find()){
                            Db::name('register_gbt')->insert($gbt_data);
                        }
                    }
                    // 处理车间项目费用信息
                    $zydqfy = $this->request->param('zydqfy');
                    $dbfy = $this->request->param('dbfy');
                    $hqfy = $this->request->param('hqfy');
                    $cj_data = array(
                        'reg_id' => $insert->id,
                        'create_time' => time(),
                        'opt_user' => $user->uname,
                        'opt_datetime' => time(),
                        'opt_name' => $user->name,
                        'zydqfy' => $zydqfy,
                        'dbfy' => $dbfy,
                        'hqfy' => $hqfy
                    );
                    if(count($cj_data)>=5 and false==Db::name('register_cj')->where('reg_id',$insert->id)->find()){
                        Db::name('register_cj')->insert($cj_data);
                    }
                    //echo '200';
                    if((int)$this->request->param('btn_type')==1){
                        $info = Register::get($insert->id);
                        $this->assign('info',$info);
                        $this->assign('cbinfo',Db::name('register_cb')->where('reg_id',$insert->id)->find());
                        $this->assign('csinfo',Db::name('register_cs')->where('reg_id',$insert->id)->find());
                        $this->assign('gbtinfo',Db::name('register_gbt')->where('reg_id',$insert->id)->find());
                        $this->assign('jsinfo',Db::name('register_js')->where('reg_id',$insert->id)->find());
                        $this->assign('cjinfo',Db::name('register_cj')->where('reg_id',$insert->id)->find());
                        $this->assign('qzrq',date('Y年m月d日'));
                        $this->assign('show',$this->request->param('show'));
                        Register::where('id',$insert->id)->update(['is_printdj'=>1]);
                        $res = ['statusCode'=>200,'message'=>'订单保存成功并打印中...'];
                    }else{
                        $res = ['statusCode'=>200,'message'=>'订单保存成功'];
                    }
                }else{
                    $res = ['statusCode'=>300,'message'=>'操作失败'];
                }
            }
        }else{
            $res = ['statusCode'=>300,'message'=>'请正确输入登记信息'];
        }
        echo json_encode($res);
    }

    // 打印订单
    public function printdj(){
        // 获取订单id
        $id = $this->request->param('id');
        $info = Register::get($id);
        $this->assign('info',$info);
        $this->assign('cbinfo',Db::name('register_cb')->where('reg_id',$id)->find());
        $this->assign('csinfo',Db::name('register_cs')->where('reg_id',$id)->find());
        $this->assign('gbtinfo',Db::name('register_gbt')->where('reg_id',$id)->find());
        $this->assign('jsinfo',Db::name('register_js')->where('reg_id',$id)->find());
        $this->assign('cjinfo',Db::name('register_cj')->where('reg_id',$id)->find());
        $this->assign('qzrq',date('Y年m月d日'));
        $this->assign('show',$this->request->param('show'));
        Register::where('id',$id)->update(['is_printdj'=>1]);
        $res = ['statusCode'=>200,'message'=>'操作完成','data'=>$this->fetch('rcyw/cjgl/printdj')];
        echo json_encode($res);
    }

    // 修改订单
    public function editdj(){
        //  值班人
        $this->assign('zbr',\app\admin\model\Zbr::all());
        //  司仪
        $this->assign('sy',\app\admin\model\Sy::all());
        //  死亡原因
        $this->assign('swyy',\app\admin\model\Swyy::all());
        //  证件
        $this->assign('zj',\app\admin\model\Zj::all());
        //  死亡日期
        $this->assign('swrq',date('Y-m-d'));
        //  证件
        $this->assign('jmlx',\app\admin\model\Jmlx::all());
        //  与逝者关系
        $this->assign('yszgx',\app\admin\model\Yszgx::all());
        //  房间号
        $this->assign('fjxx',\app\admin\model\Fjxx::all(['status'=>0]));
        //  预定炉
        $this->assign('hhl',\app\admin\model\Hhl::all());
        //  出殡方式
        $this->assign('cbfs',\app\admin\model\Cbfs::all());
        //  告别厅
        $this->assign('gbt',\app\admin\model\Gbt::all());
        //  减免类型
        $this->assign('jmlx',\app\admin\model\Jmlx::all());

        // 获取订单id
        $id = $this->request->param('id');
        $this->assign('info',Register::get($id));
        $this->assign('cbinfo',Db::name('register_cb')->where('reg_id',$id)->find());
        $this->assign('csinfo',Db::name('register_cs')->where('reg_id',$id)->find());
        $this->assign('gbtinfo',Db::name('register_gbt')->where('reg_id',$id)->find());
        $this->assign('cjinfo',Db::name('register_cj')->where('reg_id',$id)->find());

        return $this->fetch('rcyw/cjgl/editdj');
    }

    public function editdjdo(){
        $data = array(
            'id' => $this->request->param('id'),
            'djrq' => $this->request->param('djrq'),
            'xm' => $this->request->param('xm'),                // 姓名
            'xb' => $this->request->param('xb'),                // 性别
            'nl' => $this->request->param('nl'),                // 年龄
            'sfzh' => $this->request->param('sfzh'),            // 身份证号
            'jtzz' => $this->request->param('jtzz'),            // 家庭住址
            'swyy' => $this->request->param('swyy'),            // 死亡原因
            'swrq' => $this->request->param('swrq'),            // 死亡日期
            'lxr' => $this->request->param('lxr'),              // 联系人
            'yszgx' => $this->request->param('yszgx'),          // 与逝者关系
            'lxdh' => $this->request->param('lxdh'),            // 联系电话
            'zj' => $this->request->param('zj'),                // 证件
            'bz' => $this->request->param('bz'),                // 备注
            'cjfj' => $this->request->param('cjfj'),            // 车间附加
            'czybh' => $this->request->session('efing.uname'),  // 操作用户
            'czrq' => time(),                                           // 操作日期时间
            'is_dlcb' => $this->request->param('is_dlcb'),      // 是否定炉出殡
            'mz' => $this->request->param('mz'),                // 民族
            'is_bdhk' => $this->request->param('is_bdhk'),      // 是否本地户口
            'zzjgdm' => Config::get('app_zzjgdm'),              // 组织机构代码
            'lxrsfz' => $this->request->param('lxrsfz'),        // 联系人身份证
            'jmlx' => $this->request->param('jmlx'),            // 减免类型
            'sfzlx' => $this->request->param('sfzlx'),          // 身份证类型
            'gjhdq' => $this->request->param('gjhdq'),          // 国家或地区
            'dwmc' => Config::get('app_dwmc'),                  // 火化单位名称
            'kkszd' => $this->request->param('kkszd'),          // 户口所在地
        );

        if(count($data)>=19){
            $check = Register::where(['sfzh'=>$data['sfzh']])->where('id','<>',$data['id'])->find();
            if($check){
                $res = ['statusCode'=>300,'message'=>'登记信息重复'];
            }else{
                if($update = Register::update($data)){
                    $user = \app\admin\model\User::get(['uname'=>$this->request->session('efing.uname')]);
                    // 处理出殡
                    if ($data['is_dlcb']==1){
                        $hhl = \app\admin\model\Hhl::get($this->request->param('ydl'));
                        $hhllc = \app\admin\model\Hhllc::get($this->request->param('ydlc'));
                        $cbfs = \app\admin\model\Cbfs::get(['title'=>$this->request->param('cbfs')]);
                        $cb_data = array(
                            'reg_id' => $update->id,
                            'opt_user' => $user->uname,
                            'opt_datetime' => time(),
                            'opt_name' => $user->name,
                            'cbrq' => strtotime($this->request->param('cbrq')),
                        );
                        if(count($cb_data)>=5){
                            if($hhl){
                                $cb_data['ydl'] = $hhl->title;
                                $cb_data['ydlfy'] = $hhl->price;
                            }
                            if($hhllc){
                                $cb_data['ydlc'] = $hhllc->id;
                                $cb_data['ydlcid'] = $hhllc->id;
                            }
                            if($cbfs){
                                $cb_data['cbfs'] = $this->request->param('cbfs');
                                $cb_data['cbfy'] = $this->request->param('cbfy');
                                $cb_data['cbfsid'] = $cbfs->id;
                            }
                            if(false==Db::name('register_cb')->where('reg_id',$update->id)->find()){
                                $cb_data['create_time'] = time();
                                Db::name('register_cb')->insert($cb_data);
                            }else{
                                Db::name('register_cb')->where('reg_id',$update->id)->update($cb_data);
                            }
                        }
                    }else{
                        Db::name('register_cb')->where('reg_id',$update->id)->delete();
                    }
                    // 处理告别厅
                    if($gbt = $this->request->param('gbt')){
                        $gbtfy = $this->request->param('gbtfy');
                        $gbt_data = array(
                            'reg_id' => $update->id,
                            'opt_user' => $user->uname,
                            'opt_datetime' => time(),
                            'opt_name' => $user->name,
                            'gbt' => $gbt,
                            'gbtfy' => $gbtfy
                        );
                        if(count($gbt_data)>=5){
                            if(false==Db::name('register_gbt')->where('reg_id',$update->id)->find()){
                                $gbt_data['create_time'] = time();
                                Db::name('register_gbt')->insert($gbt_data);
                            }else{
                                Db::name('register_gbt')->where('reg_id',$update->id)->update($gbt_data);
                            }
                        }
                    }

                    // 处理车间项目费用信息
                    $zydqfy = $this->request->param('zydqfy');
                    $dbfy = $this->request->param('dbfy');
                    $hqfy = $this->request->param('hqfy');
                    $cj_data = array(
                        'reg_id' => $update->id,
                        'opt_user' => $user->uname,
                        'opt_datetime' => time(),
                        'opt_name' => $user->name,
                        'zydqfy' => $zydqfy,
                        'dbfy' => $dbfy,
                        'hqfy' => $hqfy
                    );
                    if(count($cj_data)>=4 and false==Db::name('register_cj')->where('reg_id',$update->id)->find()){
                        $cj_data['create_time']  = time();
                        Db::name('register_cj')->insert($cj_data);
                    }else {
                        Db::name('register_cj')->where('reg_id', $update->id)->update($cj_data);
                    }

                    $tjbtn = $this->request->param('btn_type');
                    if($tjbtn==1){
                        Register::where('id',$data['id'])->update(['qttjcjbz'=>-1]);    //返还前台
                    }
                    if($tjbtn==2){
                        Register::where('id',$data['id'])->update(['cjtjcwbz'=>1]);     // 车间提交财务
                    }

                    $res = ['statusCode'=>200,'message'=>'订单保存成功'];
                }else{
                    $res = ['statusCode'=>300,'message'=>'操作失败'];
                }
            }
            $res = ['statusCode'=>200,'message'=>'订单保存成功'];
        }else{
            $res = ['statusCode'=>300,'message'=>'请正确输入登记信息'];
        }
        echo json_encode($res);
    }

    // 删除订单
    public function deletedj(){
        $ids = explode(',',$this->request->param('ids'));
        if(count($ids)>0){
            foreach($ids as $key=>$value){
                $reg = Register::get($value);
                if($reg->djbz==1 and $reg->qttjcwbz!=1){
                    Register::destroy($value);
                    $cb = Db::name('register_cb')->where('reg_id',$value)->find();
                    Db::name('register_cb')->where('reg_id',$value)->delete();
                    Db::name('register_gbt')->where('reg_id',$value)->delete();
                    Db::name('register_cj')->where('reg_id',$value)->delete();
                    Fjxx::where('id',$cb['ydlcid'])->update(['status'=>0]);
                }
            }
            $res = ['statusCode'=>200,'message'=>'操作完成'];
        }else{
            $res = ['statusCode'=>300,'message'=>'操作失败'];
        }
        echo json_encode($res);
    }

    // 查看前台
    public function showqt(){
        $list = Register::alias('a')
            ->join('register_cs b','a.id=b.reg_id','LEFT')
            ->join('register_cb c','a.id=c.reg_id','LEFT')
            ->join('register_gbt d','a.id=d.reg_id','LEFT')
            ->join('register_js e','a.id=e.reg_id','LEFT')
            ->field('a.*,b.cs_datetime,b.cs_fjid,b.cs_price,
                                c.cbrq,c.ydl,c.ydlc,c.ydlfy,c.cbfs,c.cbfy,
                                d.gbt,d.gbtfy,e.ytysfs_id,e.ytysfs,e.jsfy')
            ->where('djbz',0)       // 只显示前台订单
            ->where('a.sy|a.xm|a.sfzh|a.jtzz|a.lxr|a.lxdh|a.zbr|a.lxrsfz|a.kkszd','like','%'.$this->request->param('keywords').'%')
            ->select();
        $totalCounts = Register::where('djbz',0)->count();
        $this->assign('list',$list);
        $this->assign('totalcounts',$totalCounts);
        return $this->fetch('rcyw/cjgl/qtlist');
    }

    // 打印出殡订单
    public function printcb(){
        $datemin = $this->request->param('datemin')?$this->request->param('datemin'):''.date('Y-m-d');
        $datemax = $this->request->param('datemax')?$this->request->param('datemax'):''.date('Y-m-d');
        if($this->request->param('datemin') or $this->request->param('datemin')){
            if($this->request->param('datemin')){
                $query1 = 'and c.cbrq>='.strtotime($datemin);
            }else{
                $query1 = '';
            }
            if($this->request->param('datemax')){
                $query2 = 'and c.cbrq<='.strtotime($datemax);
            }else{
                $query2 = '';
            }
        }else{
            $query1 = 'and c.cbrq>='.strtotime($datemin);
            $query2 = 'and c.cbrq<='.strtotime($datemax);
        }


        $list = Register::alias('a')
            ->join('register_cs b','a.id=b.reg_id','LEFT')
            ->join('register_cb c',"a.id=c.reg_id $query1 $query2")
            ->join('register_gbt d','a.id=d.reg_id','LEFT')
            ->join('register_js e','a.id=e.reg_id','LEFT')
            ->field('a.*,b.cs_datetime,b.cs_fjid,b.cs_price,
                                c.cbrq,c.ydl,c.ydlc,c.ydlfy,c.cbfs,c.cbfy,
                                d.gbt,d.gbtfy,e.ytysfs_id,e.ytysfs,e.jsfy')
            ->where('djbz',0)       // 只显示前台订单
            ->where('is_dlcb',1)       // 只显示定炉出殡的订单
            //->where('c.cbrq','between time',[$datemin,$datemax])
            ->where('a.sy|a.xm|a.sfzh|a.jtzz|a.lxr|a.lxdh|a.zbr|a.lxrsfz|a.kkszd','like','%'.$this->request->param('keywords').'%')
            ->select();
        $totalCounts = Register::where('djbz',0)->count();
        $this->assign('list',$list);
        $this->assign('totalcounts',$totalCounts);
        $this->assign('datemin',$datemin);
        $this->assign('datemax',$datemax);
        return $this->fetch('rcyw/cjgl/cblist');
    }

    // 打印出殡订单
    public function printcbdo(){
        $datemin = $this->request->param('datemin')?$this->request->param('datemin'):''.date('Y-m-d');
        $datemax = $this->request->param('datemax')?$this->request->param('datemax'):''.date('Y-m-d');
        if($this->request->param('datemin') or $this->request->param('datemin')){
            if($this->request->param('datemin')){
                $query1 = 'and c.cbrq>='.strtotime($datemin);
            }else{
                $query1 = '';
            }
            if($this->request->param('datemax')){
                $query2 = 'and c.cbrq<='.strtotime($datemax);
            }else{
                $query2 = '';
            }
        }else{
            $query1 = 'and c.cbrq>='.strtotime($datemin);
            $query2 = 'and c.cbrq<='.strtotime($datemax);
        }


        $list = Register::alias('a')
            ->join('register_cs b','a.id=b.reg_id','LEFT')
            ->join('register_cb c',"a.id=c.reg_id $query1 $query2")
            ->join('register_gbt d','a.id=d.reg_id','LEFT')
            ->join('register_js e','a.id=e.reg_id','LEFT')
            ->field('a.*,b.cs_datetime,b.cs_fjid,b.cs_price,
                                c.cbrq,c.ydl,c.ydlc,c.ydlfy,c.cbfs,c.cbfy,
                                d.gbt,d.gbtfy,e.ytysfs_id,e.ytysfs,e.jsfy')
            ->where('djbz',0)       // 只显示前台订单
            ->where('is_dlcb',1)       // 只显示定炉出殡的订单
            //->where('c.cbrq','between time',[$datemin,$datemax])
            ->where('a.sy|a.xm|a.sfzh|a.jtzz|a.lxr|a.lxdh|a.zbr|a.lxrsfz|a.kkszd','like','%'.$this->request->param('keywords').'%')
            ->select();
        $totalCounts = Register::alias('a')
            ->join('register_cs b','a.id=b.reg_id','LEFT')
            ->join('register_cb c',"a.id=c.reg_id $query1 $query2")
            ->join('register_gbt d','a.id=d.reg_id','LEFT')
            ->join('register_js e','a.id=e.reg_id','LEFT')
            ->field('a.*,b.cs_datetime,b.cs_fjid,b.cs_price,
                                c.cbrq,c.ydl,c.ydlc,c.ydlfy,c.cbfs,c.cbfy,
                                d.gbt,d.gbtfy,e.ytysfs_id,e.ytysfs,e.jsfy')
            ->where('djbz',0)       // 只显示前台订单
            ->where('is_dlcb',1)       // 只显示定炉出殡的订单
            //->where('c.cbrq','between time',[$datemin,$datemax])
            ->where('a.sy|a.xm|a.sfzh|a.jtzz|a.lxr|a.lxdh|a.zbr|a.lxrsfz|a.kkszd','like','%'.$this->request->param('keywords').'%')
            ->count();
        $this->assign('list',$list);
        $this->assign('totalcounts',$totalCounts);
        $this->assign('datemin',$datemin);
        $this->assign('datemax',$datemax);
        //return $this->fetch('rcyw/cjgl/cblist');
        $res = ['statusCode'=>200,'message'=>'操作完成','data'=>$this->fetch('rcyw/cjgl/printcb')];
        echo json_encode($res);
    }

    // 订单返还前台
    public function tjqt(){
        $ids = explode(',',$this->request->param('ids'));
        $i = 0;
        if(count($ids)>0){
            foreach($ids as $key=>$value){
                $tmp = Register::get($value);
                if($tmp->djbz==0){
                    Register::where('id',$value)->update(['qttjcjbz'=>-1,'cjfh_datetime'=>time()]);
                    $i++;
                }

            }
            if($i == 0){
                $res = ['statusCode'=>300,'message'=>'请选择前台订单执行该操作'];
            }else{
                $res = ['statusCode'=>200,'message'=>'操作完成'];
            }

        }else{
            $res = ['statusCode'=>300,'message'=>'操作失败'];
        }
        echo json_encode($res);
    }

    // 提交财务
    public function tjcw(){
        $ids = explode(',',$this->request->param('ids'));
        if(count($ids)>0){
            foreach($ids as $key=>$value){
                Register::where('id',$value)->update(['cjtjcwbz'=>1,'tjcw_datetime'=>time()]);
            }
            $res = ['statusCode'=>200,'message'=>'操作完成'];
        }else{
            $res = ['statusCode'=>300,'message'=>'操作失败'];
        }
        echo json_encode($res);
    }



}